home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Activation / Activator.cp < prev    next >
Text File  |  2000-06-23  |  1KB  |  72 lines

  1. // Activator.cp
  2.  
  3. #ifndef Activator_h
  4. #include "Activator.h"
  5. #endif
  6. #ifndef Focus_h
  7. #include "Focus.h"
  8. #endif
  9.  
  10. Activator::Activator( Focus& focus )
  11.   : Enableable( !focus.Active() ),
  12.          // We can't call Activate() yet, so we start disabled
  13.          // if we're connected to an active focus.
  14.      active( false ),
  15.      focusActive( focus.Active() ),
  16.      link( this )
  17.   {
  18.     focus.activators.Add( link, afterEnd );
  19.   }
  20.  
  21. Activator::~Activator()
  22.   {
  23.   }
  24.  
  25. void Activator::FocusActivated()
  26.   {
  27.     Assert( !focusActive );
  28.     Assert( !active );
  29.     
  30.     focusActive = true;
  31.     if ( Enabled() )
  32.       {
  33.         active = true;
  34.         Activate();
  35.       }
  36.   }
  37.  
  38. void Activator::FocusDeactivated()
  39.   {
  40.     Assert( focusActive );
  41.     Assert( active == Enabled() );
  42.     
  43.     focusActive = false;
  44.     if ( Enabled() )
  45.       {
  46.         active = false;
  47.         Deactivate();
  48.       }
  49.   }
  50.  
  51. void Activator::BeEnabled()
  52.   {
  53.     Assert( !active );
  54.  
  55.     if ( focusActive )
  56.       {
  57.         active = true;
  58.         Activate();
  59.       }
  60.   }
  61.  
  62. void Activator::BeDisabled()
  63.   {
  64.     Assert( focusActive == active );
  65.     
  66.     if ( focusActive )
  67.       {
  68.         active = false;
  69.         Deactivate();
  70.       }
  71.   }
  72.